package org.jivesoftware.smack.packet;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.util.StringUtils;

public class RosterPacket extends IQ
{
  private final List<Item> rosterItems = new ArrayList();
  private String version;

  public void addRosterItem(Item paramItem)
  {
    synchronized (this.rosterItems)
    {
      this.rosterItems.add(paramItem);
    }
  }

  public String getVersion()
  {
    return this.version;
  }

  public void setVersion(String paramString)
  {
    this.version = paramString;
  }

  public int getRosterItemCount()
  {
    synchronized (this.rosterItems)
    {
      return this.rosterItems.size();
    }
  }

  public Collection<Item> getRosterItems()
  {
    synchronized (this.rosterItems)
    {
      return Collections.unmodifiableList(new ArrayList(this.rosterItems));
    }
  }

  public String getChildElementXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<query xmlns=\"jabber:iq:roster\" ");
    if (this.version != null)
      localStringBuilder.append(" ver=\"" + this.version + "\" ");
    localStringBuilder.append(">");
    synchronized (this.rosterItems)
    {
      Iterator localIterator = this.rosterItems.iterator();
      while (localIterator.hasNext())
      {
        Item localItem = (Item)localIterator.next();
        localStringBuilder.append(localItem.toXML());
      }
    }
    localStringBuilder.append("</query>");
    return localStringBuilder.toString();
  }

  public static class Item
  {
    private String user;
    private String name;
    private RosterPacket.ItemType itemType;
    private RosterPacket.ItemStatus itemStatus;
    private final Set<String> groupNames;

    public Item(String paramString1, String paramString2)
    {
      this.user = paramString1.toLowerCase();
      this.name = paramString2;
      this.itemType = null;
      this.itemStatus = null;
      this.groupNames = new CopyOnWriteArraySet();
    }

    public String getUser()
    {
      return this.user;
    }

    public String getName()
    {
      return this.name;
    }

    public void setName(String paramString)
    {
      this.name = paramString;
    }

    public RosterPacket.ItemType getItemType()
    {
      return this.itemType;
    }

    public void setItemType(RosterPacket.ItemType paramItemType)
    {
      this.itemType = paramItemType;
    }

    public RosterPacket.ItemStatus getItemStatus()
    {
      return this.itemStatus;
    }

    public void setItemStatus(RosterPacket.ItemStatus paramItemStatus)
    {
      this.itemStatus = paramItemStatus;
    }

    public Set<String> getGroupNames()
    {
      return Collections.unmodifiableSet(this.groupNames);
    }

    public void addGroupName(String paramString)
    {
      this.groupNames.add(paramString);
    }

    public void removeGroupName(String paramString)
    {
      this.groupNames.remove(paramString);
    }

    public String toXML()
    {
      StringBuilder localStringBuilder = new StringBuilder();
      localStringBuilder.append("<item jid=\"").append(this.user).append("\"");
      if (this.name != null)
        localStringBuilder.append(" name=\"").append(StringUtils.escapeForXML(this.name)).append("\"");
      if (this.itemType != null)
        localStringBuilder.append(" subscription=\"").append(this.itemType).append("\"");
      if (this.itemStatus != null)
        localStringBuilder.append(" ask=\"").append(this.itemStatus).append("\"");
      localStringBuilder.append(">");
      Iterator localIterator = this.groupNames.iterator();
      while (localIterator.hasNext())
      {
        String str = (String)localIterator.next();
        localStringBuilder.append("<group>").append(StringUtils.escapeForXML(str)).append("</group>");
      }
      localStringBuilder.append("</item>");
      return localStringBuilder.toString();
    }
  }

  public static class ItemStatus
  {
    public static final ItemStatus SUBSCRIPTION_PENDING = new ItemStatus("subscribe");
    public static final ItemStatus UNSUBSCRIPTION_PENDING = new ItemStatus("unsubscribe");
    private String value;

    public static ItemStatus fromString(String paramString)
    {
      if (paramString == null)
        return null;
      paramString = paramString.toLowerCase();
      if ("unsubscribe".equals(paramString))
        return UNSUBSCRIPTION_PENDING;
      if ("subscribe".equals(paramString))
        return SUBSCRIPTION_PENDING;
      return null;
    }

    private ItemStatus(String paramString)
    {
      this.value = paramString;
    }

    public String toString()
    {
      return this.value;
    }
  }

  public static enum ItemType
  {
    none, to, from, both, remove;
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smack.packet.RosterPacket
 * JD-Core Version:    0.6.1
 */